package com.bluesky.plum.domain.tool;

import com.bluesky.plum.validate.ParameterValidateFailedException;
import com.bluesky.plum.validate.ValidationError;

/**
 * this is a simple BusinessObject, no entity involved
 * 
 * @author HZ00260
 * 
 */
public class CalculatorImpl implements Calculator {

	public Integer add(Integer a, Integer b) {
		int c = a + b;
		System.out.println("result=" + c);
		return c;
	}

	/**
	 * this method will throw ParameterValidateFailedException. so the caller
	 * can get the validation error list.
	 */
	public Integer divide(Integer a, Integer b) {
		// check the parameter
		if (b == 0) {
			ParameterValidateFailedException e = new ParameterValidateFailedException();
			e.addValidationError(new ValidationError("b",
					"b shouldn't be zero as divider"));
			throw e;
		}
		int c = a / b;
		System.out.println("result=" + c);
		return c;
	}

	public Integer sub(Integer a, Integer b) {
		int c = a - b;
		System.out.println("result=" + c);
		return c;
	}

}
